package com.nobody.facepk.service;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;

@Service
public class ServiceRegistry implements ApplicationContextAware{
	private static ApplicationContext context;
	
	private static UserService userService;
	private static PictureService pictureService;
	private static PictureManager pictureManager;
	private static EventService eventService;
	private static CommentService commentService;
	
	private static GeneralDaoService generalDaoService;
	
	public static UserService getUserService() {
		if(userService==null) {
			userService = context.getBean(UserService.class);
		}
		return userService;
	}
	
	public static CommentService getCommentService() {
		if(commentService==null) {
			commentService = context.getBean(CommentService.class);
		}
		return commentService;
	}
	
	public static EventService getEventService() {
		if(eventService==null) {
			eventService = context.getBean(EventService.class);
		}
		return eventService;
	}
	
	public static PictureService getPictureService() {
		if(pictureService==null) {
			pictureService = context.getBean(PictureService.class);
		}
		return pictureService;
	}
	
	public static PictureManager getPictureManager() {
		if(pictureManager==null) {
			pictureManager = context.getBean(PictureManager.class);
		}
		return pictureManager;
	}
	
	public static GeneralDaoService getGeneralDaoService() {
		if(generalDaoService==null) {
			generalDaoService = context.getBean(GeneralDaoService.class);
		}
		return generalDaoService;
	}
	
	@Override
	public void setApplicationContext(ApplicationContext c) throws BeansException {
		context = c;
	}

}
